package metartest;


import helper.Proxy;

import javax.swing.JOptionPane;

import base.AppMemory;


import metar.MetarInfo;
import metar.MetarLogException;
import metar.MetarParseException;
import metar.MetarReader;
import model.WeatherModel;

/**
 * Testprogramm für MetarReader => Consolenprogramm
 * @author Michel Metzger, Java-Kurs 2013
 * @version 1.0.0
 *
 */
public class ConsoleTestRun {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		/**
		 * Konfigurationsdaten in AppMemory setzen
		 */
		if (!AppMemory.loadConfig()) {
			System.exit(0);
		}

		/**
		 * alfa traning Proxy setzen
		 */
		Proxy.setProxy();

		/**
		 * einige Beispiel-Airports
		 */
		String[] airports = { "EDDS", "EDDM", "KLOZ", "EDDI", "EHAM" };
		
		for (String s : airports) {
			try {
				WeatherModel wm = new MetarReader(s).getMetarInfo();
	
				if (wm != null) {
					System.out.println("=================================================");
					System.out.println("WeatherModel");
					System.out.println("=================================================");
					System.out.println("cityId=" + wm.getCityID());
					System.out.println("info=" + wm.getInfo());
					System.out.println("observationTime=" + wm.getObservationTime());
					System.out.println("timeStamp=" + wm.getTimeStamp());
					System.out.println("date=" + wm.getDate());
					System.out.println("temperature=" + wm.getTemperature() + "°C");
					System.out.println("airPressure=" + wm.getAirPressure() + "hPa");
					System.out.println("windDirectionInfo=" + wm.getWindDirectionInfo());
					System.out.println("cloudiness=" + wm.getCloudiness());
					System.out.println("visibility=" + wm.getVisibility());
					System.out.println("=================================================\n\n");
				}
			} catch (MetarLogException e) {
				if (MetarInfo.isDebugMode()) {
					e.printStackTrace();
				}
				JOptionPane.showMessageDialog(null, e.getMessage(), "Error while writing logfile", JOptionPane.ERROR_MESSAGE);
			} catch (MetarParseException e) {
				if (MetarInfo.isDebugMode()) {
					e.printStackTrace();
				}
				JOptionPane.showMessageDialog(null, e.getMessage(), "Error while parsing metar info", JOptionPane.ERROR_MESSAGE);
			}
		}
	}
	
}
